import 'package:get/get.dart';
import 'package:gt_flutter_admin/app/routes.dart';

import '../utils/storage_utils.dart';

class EnsureAuthMiddleware extends GetMiddleware {
  @override
  Future<GetNavConfig?> redirectDelegate(GetNavConfig route) async {
    if (!StorageUtils.isLogin()) {
      return GetNavConfig.fromRoute(Routes.LOGIN);
    }

    return await super.redirectDelegate(route);
  }
}

class EnsureNotAuthedMiddleware extends GetMiddleware {
  @override
  Future<GetNavConfig?> redirectDelegate(GetNavConfig route) async {
    if (StorageUtils.isLogin()) {
      return null;
    }

    return await super.redirectDelegate(route);
  }
}
